<include file="Public/header" /> 

<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
	<include file="Public/sidebar" /> 
	<!--左侧菜单//-->
	
	<!-- mainCon -->
	<div id="mainCon" class="mainCon">
		<h4>编辑会员购买信息</h4>
		<form class="form-horizontal" id="myform">
			<!-- <div class="form-group">
				<label for="mobile" class="col-sm-2 control-label">编号ID</label>
				<div class="col-sm-5">
					<p class="form-control-static text-info" style="padding-left:5px;" ><{$level_info['level_id']}></p>
				</div>
			</div> -->

			<div class="form-group">
				<label for="level_name" class="col-sm-2 control-label">等级名称</label>
				<div class="col-sm-5">
					<div>
					<input type="text" class="form-control select-input" name="level_name" id="level_name" value="<{$level_info['level_name']}>" placeholder="等级名称" defaultValue="<{$level_info['level_name']}>" >
					</div>
				</div>
			</div>

			<div class="form-group">
				<label for="price" class="col-sm-2 control-label">价格 (元)</label>
				<div class="col-sm-5">
					<div class="input-group">
					<span class="glyphicon-yen input-group-addon"></span>
					<input type="text" class="form-control select-input" name="price" id="price" value="<{$level_info['price']}>" placeholder="购买价格" defaultValue="<{$level_info['price']}>" >
					<span class="input-group-addon">元</span>
					</div>
				</div>
			</div>

			<div class="form-group">
				<label for="valid_time" class="col-sm-2 control-label">有效期 (月)</label>
				<div class="col-sm-5">
					<div class="input-group">
					<input type="text" class="form-control select-input" name="valid_time" id="valid_time" placeholder="月数" value="<{$level_info['valid_time']}>" defaultValue="<{$level_info['valid_time']}>" >
					<span class="input-group-addon">个月</span>
					</div>
				</div>
			</div>

			<div class="form-group">
				<label for="note" class="col-sm-2 control-label">等级详细描述</label>
				<div class="col-sm-5">
					<textarea id="note" name="note" class="form-control select-input" placeholder="详细描述" defaultValue="<{$level_info['note']}>" rows="3" style="resize: none;"><{$level_info['note']}></textarea>
				</div>
			</div>
			
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<input type="hidden" name="level_id" value="<{$level_info['level_id']}>" />
					<button type="submit" class="btn btn-default col-sm-2">保存</button>
					<button type="button" class="btn btn-default col-sm-2 col-md-offset-1" onclick="window.location.href='<{:U('Admin/Option/levelList',array('k'=>6,'sk'=>6))}>'" >取消</button>
				</div>
			</div>
		</form>
		
	</div>
	<!-- mainCon// -->
	
</div>
<!--主窗体//-->

<script src="__PUBLIC__/js/layer/layer.js"></script>
<script src="__PUBLIC__/js/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/validate/messages_zh.js"></script>
<script>
$(function(){
	
	$('#password').on('click', function(){
	    var that = this;
	    layer.tips('密码长度由6-20字符组成,留空表示不修改密码。', that, {
		    tips: [2, '#3595CC'],
		});
	});

	$('#valid_time').focus(function() {
		layer.tips('0为终身有效','#valid_time');
	});
	
	$("#myform").validate({
		rules: {
			level_name: {
				required: true,
			},
			price: {
				required: true,
				number: true,
				min: 1
			},
			valid_time: {
				required: true,
				digits: true
			},
			note: {
				required: true,
			}
		},
		errorPlacement: function(error, element) {    
			error.appendTo(element.parent().parent());    
		},
		submitHandler : function(form){
			var ajaxUrl = "<{:U('Admin/Option/changeLevelInfo')}>";

			layer.confirm('确定提交更改！', {icon: 3}, function(index) {
				$.post(ajaxUrl,$(form).serialize(),function(r){
					if (r.error == 1){
						layer.alert(r.errmsg,{icon: 2});
					}else{
						layer.alert(r.errmsg,{icon: 1},function(index){
							location.reload();
							// layer.close(index);
						});
					}
					return false;
				});
			});
        	return false
		}
	});

	// 输入框值变更提示
	$('.select-input').change(function(event) {
		if ($(this).val() != $(this).attr('defaultValue'))
		{
			$(this).parent().addClass('has-warning');
		}
		else
		{
			$(this).parent().removeClass('has-warning');
		}
	});

	// 会员等级
	var level_list_validate = new Array();
	<?php foreach ($level_list as $key => $row): ?>
	level_list_validate[<{$key}>]="<{$row['valid_time']}>";
	<?php endforeach ?>
});
</script>

<include file="Public/footer" /> 